package cn.yjr.vector.tools;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;

/**
 * @author vector
 *
 */
public class ImageViewDrawableAware extends ImageViewAware {

    public ImageViewDrawableAware(ImageView imageView) {
        super(imageView);
    }

    @Override
    public int getWidth() {
        Drawable drawable = imageViewRef.get().getDrawable();
        return drawable!=null ? drawable.getIntrinsicWidth() : super.getWidth();
    }

    @Override
    public int getHeight() {
        Drawable drawable = imageViewRef.get().getDrawable();
        return drawable!=null ? drawable.getIntrinsicHeight() : super.getHeight();
    }

    public boolean setImageBitmap(Bitmap bitmap) {
        ImageView imageView = imageViewRef.get();
        int viewWidth = imageView.getDrawable().getIntrinsicWidth();
        int viewHeight = imageView.getDrawable().getIntrinsicHeight();

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        return super.setImageBitmap(bitmap);
    }
}